var core = require('core');
var db = core.db;
var send = core.send;
var getToken = function(req, res, next){

    var body = req.body;
    var type = body.type;
    var token = body.token;
    // var data = JSON.parse(body.data);
    delete body.token;
    delete body.type;
    var SEND;
//, "-_id -__v -expires -token"
    db.schema[type].findOneAndUpdate({token: token}, body, {upsert: false}, function(err, doc){
        if(err){
            SEND = new send(100000);
            console.error(err);
        }else{
            SEND = new send(0);
            SEND.docs = doc;
        };

        res.send(SEND);
    });

};

module.exports = getToken;
